package com.ruoyi.know.mapper;

import com.ruoyi.know.domain.ImSingle;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ImSingleMapper {

	@Select("select * from im_single where (fromuser = #{fromUser} and touser = #{toUser}) or (fromuser = #{toUser} and touser = #{fromUser})")
	List<ImSingle> findByUsername(@Param("fromUser") String fromUser, @Param("toUser") String toUser);

	@Select("select * from im_single where touser = #{toUser} and readed = 0")
	List<ImSingle> findByToUsername(String toUser);

	/**
	 * 插入单聊记录
	 * @param imSingle 单聊记录实体
	 * @return 插入成功的记录数
	 */
	int insert(ImSingle imSingle);

	/**
	 * 根据 ID 更新单聊记录
	 * @param imSingle 单聊记录实体
	 * @return 更新成功的记录数
	 */
	int updateById(ImSingle imSingle);
}
